from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import Screen,ScreenManager
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.image import Image
people_list = ['a','boy','girl','father','mother','f','h','k']


class Peoplelaout:
    def people(self):
        finerout = BoxLayout()
        people = GridLayout(cols=1, spacing=[0, 0],  padding=[1, 0, 0, 0])
        for i in people_list:
            _cat = Button(text=i, on_press=lambda e: print("开始聊天"))
            people.add_widget(_cat)
        finerout.add_widget(people)
        return finerout
class Smanagelayout(ScreenManager):
    def home(self):
        self.sm = ScreenManager()
        screen1_layout = Screen(name='1')
        screen2_layout = Screen(name='2')
        screen3_layout = Screen(name='3')
        screen4_layout = Screen(name='4')
        self.home_layout = BoxLayout(orientation="vertical")
        textlayout = BoxLayout()
        textlayout.add_widget(self.sm)
        button_layout = BoxLayout(size_hint_max_y="100dp")
        pe = Peoplelaout().people()
        screen2_layout.add_widget(pe)
        mainbutton = Button(text='1',background_normal=('imgs/1.jpeg'))
        mainbutton.bind(on_press=self.screen1_layout_)
        peoplebutton = Button(text='2',background_normal=('imgs/2.jpeg'))
        peoplebutton.bind(on_press=self.screen2_layout_)
        button3 = Button(text='3',background_normal=('imgs/3.jpeg'),)
        button3.bind(on_press=self.screen3_layout_)
        button4 = Button(text='4',background_normal=('imgs/4.jpeg'))
        button4.bind(on_press=self.screen4_layout_)
        button_layout.add_widget(mainbutton)
        button_layout.add_widget(peoplebutton)
        button_layout.add_widget(button3)
        button_layout.add_widget(button4)
        imgbox = BoxLayout()
        imgbox.add_widget(Image(source='ps5.jpg',keep_ratio=False,allow_stretch=True))
        screen3_layout.add_widget(imgbox)
        screen1_boxlayout = BoxLayout()
        screen1_boxlayout.add_widget(TextInput(text='WXHOME'))
        screen1_layout.add_widget(screen1_boxlayout)
        self.sm.add_widget(screen1_layout)
        self.sm.add_widget(screen2_layout)
        self.sm.add_widget(screen3_layout)
        self.home_layout.add_widget(textlayout)
        self.home_layout.add_widget(button_layout)

        return self.home_layout



    def screen2_layout_(self,instance):
        self.sm.current = '2'

    def screen1_layout_(self,instance):
        self.sm.current = '1'
    def screen3_layout_(self,instance):
        self.sm.current = '3'
    def screen4_layout_(self,instance):
        self.sm.current = '4'
class MyApp(App):
    def build(self):
        sm = Smanagelayout().home()
        return sm
MyApp().run()
